package GRPC

import (
	"fmt"
	"gin/global"
	order "gin/internal/pb/order"
	pb "gin/internal/pb/user"
	"gin/tools"
	"google.golang.org/grpc"
)

func UserClient() {

	consul, err := tools.NewConsul("117.27.231.169", 8500)
	if err != nil {
		return
	}
	fromConsul, err := consul.GetServiceFromConsul("userServer")
	if err != nil {
		return
	}
	fmt.Println(fromConsul)

	// 1.连接
	conn, err := grpc.Dial(fromConsul, grpc.WithInsecure())
	if err != nil {
		fmt.Printf("连接异常： %s\n", err)
	}
	// 2. 实例化gRPC客户端
	global.UserClient = pb.NewUserClient(conn)

}
func OrderClient() {

	// 1.连接
	conn, err := grpc.Dial("127.0.0.1:50052", grpc.WithInsecure())
	if err != nil {
		fmt.Printf("连接异常： %s\n", err)
	}
	// 2. 实例化gRPC客户端
	global.OrderClient = order.NewOrderClient(conn)

}
